package com.ymttest.database.mongo;

import java.util.ArrayList;

import com.mongodb.MongoClientURI;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;
import com.ymttest.utils.EnvSetup;

/**
 * set4a:SmsProxyDB表名：ApplicationConfig
 * 
 * @author chenjiazhu
 *
 */
public class ApplicationConfigWapper {
	MongoDBDriver mdd;

	public ApplicationConfigWapper() throws Exception {
		mdd = new MongoDBDriver(new MongoClientURI(EnvSetup.getSystemUrl("set5smsmongourl")));
		mdd.selectCollection("ApplicationConfig");
	}

	/**
	 * 用appid查询整条记录
	 * 
	 * @param appid
	 * @return ApplicationConfigBean
	 * @throws Exception
	 */
	public ApplicationConfigBean getCollectionByIdAndAppId(String id,String appid) throws Exception {
		String re = null;
		ApplicationConfigBean bean = null;
		String filter="{\"_id\":\""+id+"\",\"AppId\":\"" + appid + "\"}";
		ArrayList<String> list = mdd.selectPart(filter);
		Logger.debug("getCollectionByIdAndAppId filter : "+filter);
		try {
			if (list.size() > 0) {
				re = list.get(0);
				bean = (ApplicationConfigBean) FormatUtil.GSONToObject(re, ApplicationConfigBean.class);
				return bean;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
